home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Essentials / Miscellaneous Disk Images / Apple II Getting down to Basic / PROGRAM.TEXT.txt < prev    next >
Encoding:
Text File  |  1983-10-25  |  4.2 KB  |  314 lines

  1. %
  2. 3
  3. 10
  4. 1
  5. 38
  6.        WRITING PROGRAMS
  7.  
  8. With Applesoft BASIC, you can do 
  9. things now or you can do them 
  10. later.
  11. ^
  12. &
  13.  
  14.  
  15. When you type a statement like...
  16. ^
  17. %
  18. 3
  19. 12
  20. 1
  21. 38
  22. ...the computer carries out your
  23. instructions right now.  That is, 
  24. your instructions are carried out 
  25. by the computer immediately after
  26. you press RETURN.  This is called 
  27. (logically enough) IMMEDIATE 
  28. EXECUTION.
  29. ^
  30. &
  31. Immediate execution is fine if
  32. you want immediate results.
  33. But what if you want to put 
  34. several statements together and 
  35. store them until later? 
  36. ^
  37. %
  38. 3
  39. 9
  40. 1
  41. 38
  42. You must use DEFERRED EXECUTION
  43. if you want to make your Apple //e 
  44. save statements for later use.
  45. ^
  46. &
  47. Deferred execution means that you 
  48. tell the computer to store your 
  49. instructions until you give the 
  50. go-ahead to execute them.
  51. ^
  52. &
  53. To write an instruction in 
  54. deferred execution, simply type 
  55. a number in front of the 
  56. statement.  For instance... 
  57. ^
  58. &
  59. When you press RETURN, nothing
  60. happens on the screen.
  61. But the statement is stored in 
  62. the computer's memory. 
  63. ^
  64. &
  65.  
  66. To execute the PRINT statement,
  67. type... 
  68. ^
  69. &
  70. The RUN command causes the 
  71. Apple //e to execute all of the
  72. statements stored in memory.
  73. ^
  74. &
  75. Any time you put numbers in front
  76. of one or more statements, the 
  77. resulting lines are stored in
  78. memory as a PROGRAM.  
  79. ^
  80. &
  81. The number of the statement (in
  82. this case 10) is called the LINE
  83. NUMBER.
  84. ^
  85. &
  86. You can add another line by typing
  87. another line number and a 
  88. statement.  For instance...
  89. ^
  90. &
  91. Please execute the new program
  92. (the command to execute a program
  93. is RUN).
  94. ^
  95. %
  96. 3
  97. 8
  98. 1
  99. 38
  100. Very good!  You just ran an
  101. Applesoft BASIC program.
  102. ^
  103. &
  104. Notice that line number 10 was 
  105. executed first, and line 30 was
  106. executed second.
  107. ^
  108. &
  109. BASIC executes statements in the 
  110. order of the line numbers, begin-
  111. ning with the smallest number.
  112. ^
  113. &
  114. Now let's say you want to insert a
  115. line between line 10 and line 30.
  116. No problem!  Just type...
  117. ^
  118. %
  119. 3
  120. 10
  121. 1
  122. 38
  123. The line numbers indicate the 
  124. order in which the lines are
  125. executed, so line 20 will 
  126. print between line 10 and 
  127. line 30.
  128. ^
  129. %
  130. 3
  131. 8
  132. 1
  133. 38
  134. Type RUN and notice that the
  135. lines print in the order of
  136. the line numbers.
  137. ^
  138. %
  139. 3
  140. 9
  141. 1
  142. 38
  143. Wonderful!  You can see that 
  144. the lines were indeed printed 
  145. in the correct order.
  146. ^
  147. Now it's up to you to finish
  148. this verse with one more PRINT
  149. statement.  Please type your
  150. statement on line 40.
  151. ^
  152. %
  153. 3
  154. 7
  155. 1
  156. 38
  157. Hey, you're really getting the
  158. hang of it, 
  159. ^
  160. %
  161. 3
  162. 11
  163. 1
  164. 38
  165. Every program should end with
  166. an END statement.  The END
  167. statement tells the computer that
  168. the program is finished and
  169. that it doesn't have any more
  170. work to do. 
  171. ^
  172. %
  173. 3
  174. 7
  175. 1
  176. 38
  177. To add the END statement, type
  178. a line number and the word END.
  179. ^
  180. &
  181. Your program is now complete. 
  182. Why don't you run it.
  183. ^
  184. %
  185. 3
  186. 10
  187. 1
  188. 38
  189. The computer stops when it reaches
  190. line 50, the END statement.
  191. Notice that END isn't printed
  192. when the program is run because it 
  193. isn't part of a PRINT statement.
  194. ^
  195. %
  196. 3
  197. 10
  198. 1
  199. 38
  200. But what if you want to look
  201. at all the program statements
  202. after you've typed them into
  203. memory?  It's easy.  You just
  204. type...
  205. ^
  206. %
  207. 3
  208. 8
  209. 1
  210. 38
  211. The LIST command shows all of
  212. the program lines in memory in
  213. the correct order.
  214. ^
  215. &  
  216. Changing and deleting program 
  217. lines is a snap.
  218. ^
  219. &
  220. Let's say you've decided that
  221. your rhyme could be improved 
  222. by changing line 40.
  223. ^
  224. &
  225. To change the line, just type
  226. the line number and type a new
  227. PRINT statement.
  228. ^
  229. &
  230. Why not try it now. Change
  231. line 40 by typing 40 and a new
  232. PRINT statement.
  233. ^
  234. %
  235. 3
  236. 8
  237. 1
  238. 38
  239. You did it!
  240. Now type LIST to make sure 
  241. that your program did change.
  242. ^
  243. %
  244. 3
  245. 8
  246. 1
  247. 38
  248. Notice that the new line 40
  249. is substituted for the old
  250. line 40.
  251. ^
  252. %
  253. 3
  254. 6
  255. 1
  256. 38
  257. Now run the new program.
  258. ^
  259. %
  260. 3
  261. 10
  262. 1
  263. 38
  264. You're doing VERY well!
  265. Deleting lines is just as easy.  
  266. To delete a line, simply type 
  267. the line number of the line you
  268. want to delete and press RETURN.
  269. ^
  270. &
  271. For instance, if you decide that 
  272. you don't want line 30 in your 
  273. program, you can erase it by 
  274. typing 30 and pressing RETURN.  
  275. Try erasing line 30 now.
  276. ^
  277. %
  278. 3
  279. 7
  280. 1
  281. 38
  282. Excellent!  Now list the
  283. program.
  284. ^
  285. %
  286. 3
  287. 7
  288. 1
  289. 38
  290. You can see that you have
  291. deleted line 30.
  292. ^
  293. %
  294. 3
  295. 9
  296. 1
  297. 38
  298. You may be upset that you just
  299. lost a line of your poem. Press 
  300. RETURN and we'll do you a favor 
  301. and retype line 30 for you.
  302. ^
  303. &
  304. There you go.  Your program is 
  305. back to its original elegance.
  306. ^
  307. &
  308. The next step is to save your
  309. program.  Press RETURN to go to
  310. the next section, or press ESC
  311. to go back to the menu.
  312. ^
  313.